home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / mail / listserv / utils / check_addr.pl.Z / check_addr.pl
Encoding:
Internet Message Format  |  1992-12-14  |  3.8 KB

  1. From List-Managers-Owner@GreatCircle.COM Tue Dec 15 09:10:08 1992
  2. Return-Path: <List-Managers-Owner@GreatCircle.COM>
  3. Received: from relay1.UU.NET by cs-mail.bu.edu (5.61+++/SMI-4.0.3)
  4.     id AA15722; Tue, 15 Dec 92 09:10:00 -0500
  5. Received: from mycroft.GreatCircle.COM by relay1.UU.NET with SMTP 
  6.     (5.61/UUNET-internet-primary) id AA25701; Tue, 15 Dec 92 08:56:07 -0500
  7. Received: by mycroft.GreatCircle.COM (4.1/SMI-4.1/Brent-921015)
  8.     id AA24232; Tue, 15 Dec 92 05:39:40 PST
  9. Received: from note2.nsf.gov by mycroft.GreatCircle.COM (4.1/SMI-4.1/Brent-921015)
  10.     id AB24211; Tue, 15 Dec 92 05:38:25 PST
  11. Received: from z.nsf.gov by Note2.nsf.gov id aa26305; 15 Dec 92 8:34 EST
  12. Received: by z.nsf.gov (4.1/SMI-4.1)
  13.     id AA24138; Tue, 15 Dec 92 08:36:27 EST
  14. Message-Id: <9212151336.AA24138@z.nsf.gov>
  15. From: "Michael H. Morse" <mmorse@z.nsf.gov>
  16. Date: Tue, 15 Dec 1992 08:36:27 EST
  17. In-Reply-To: Gene Rackow <rackow@antares.mcs.anl.gov>
  18.        "Re: How to deal with bounces" (Dec 14, 10:09pm)
  19. X-Mailer: Mail User's Shell (7.1.1 5/02/90)
  20. To: Gene Rackow <rackow@antares.mcs.anl.gov>,
  21.         Gess Shankar <gess@knex.gwinnett.com>
  22. Subject: Re: How to deal with bounces
  23. Cc: list-managers@GreatCircle.COM
  24. Sender: List-Managers-Owner@GreatCircle.COM
  25. Precedence: bulk
  26. Status: R
  27.  
  28.  
  29. > Something that I've been thinking about adding into majordomo is a
  30. > way to have a list of addreses to check before adding them to the
  31. > list.  If the address is in the bozo list, the request will be
  32. > denied with some message (possibly) until the list maintainer has
  33. > been notified that the bozo address has been corrected in a way suitable
  34. > to both parties.  There are some addresses that keep popping up bad
  35. > and the user keeps sending in subscribe me messages just to stay on the
  36. > list, even though his address, or something, is flakey at best.
  37.  
  38. Does majordomo check addresses at all before putting them on the list?
  39. I'm pretty sure that Listserv for Unix does not.  I have a little
  40. Perl script (I'm starting to sound like a broken record) that uses
  41. nslookup to at least check that the host name is in the DNS.  That
  42. has almost totally cut out bounces on a non-listserv system I run.
  43. If anyone's interested, I've included it here.  It's not perfect, but
  44. it does most of the job.
  45.  
  46. --Mike
  47.  
  48. #!/usr/local/bin/perl
  49. # a script to check a mail address
  50. # returns 0 if OK (far as we know)
  51. # returns 1 if not.
  52.  
  53. $debug = 0;
  54. $tmp = "/tmp/chkaddr$$";
  55. if ($#ARGV != 0){
  56.    print("usage: check_addr address\n");
  57.    &leave(1);
  58. }
  59. $test = $ARGV[0];
  60.  
  61. # actually, the first two tests, for 1) embedded spaces and 
  62. # 2) no @ sign will never fail, because download prevents
  63. # spaces, and adds "@nsf.gov" to addresses without an @.
  64.  
  65. # does it have spaces?
  66. $num_spaces = $test =~ tr/ / /;
  67. if ($num_spaces){
  68.    &leave(1);
  69. }
  70.  
  71. # does it have an @?
  72. $num_ats = $test =~ tr/\@/\@/;
  73. if ($num_ats != 1){
  74.    &leave(1);
  75. }
  76.  
  77. # does it have a rhs and lhs?
  78. ($lhs,$rhs) = split(/@/,$test);
  79. if (! $lhs || ! $rhs) {     # must have both a rhs and lhs
  80.    &leave(1);
  81. }
  82.  
  83. # does the rhs have dots?
  84. $num_dots = $rhs =~ tr/././;
  85. if (! $num_dots) {
  86.    &leave(1);
  87. }
  88.  
  89. # if it has just one dot, does it end with "BITNET"?
  90. if ($num_dots == 1) {
  91.    if ($rhs =~ /\.bitnet$/i) {
  92.       &leave(0);
  93.    }
  94. }
  95.  
  96. # OK, everything looks pretty good, let's try nslookup
  97. open(LOOK,"|/usr/etc/nslookup > $tmp 2>$tmp") || &leave(1);
  98. print LOOK<<EOM;
  99. $rhs
  100. set querytype=MX
  101. $rhs
  102. EOM
  103. close(LOOK);
  104. open(IN,$tmp) || &leave(1);
  105. while(<IN>){    # look at non-MX query
  106.    if (/^> >/){
  107.       last;
  108.    }
  109.    if (/^Name/) {
  110.       $try = <IN>;
  111.       if ($try =~ /^> >/){
  112.          last;               # shouldn't happen
  113.       }
  114.       if ($try =~ /^Address:\s+\d+\./) { # looks good
  115.          &leave(0);
  116.       }
  117.    }
  118. }
  119. while(<IN>){    # look at MX query
  120.    chop;
  121.    if (/mail exchanger =/){
  122.       &leave(0);
  123.    }
  124. }
  125. &leave(1);
  126.  
  127.  
  128. sub leave {
  129.    if($debug){
  130.       print("Exit $_[0].\n");
  131.    }
  132.    if( -e $tmp) {
  133.       unlink($tmp);
  134.    }
  135.    exit ($_[0]);
  136. }
  137.  
  138.